package com.mango.algorithm.hash;

import com.google.common.base.Charsets;
import com.google.common.hash.Hashing;

import java.nio.charset.Charset;

/**
 * hash函数测试
 * @Author: mango
 * @Date: 2022/5/18 11:48 下午
 */
public class GuavaHashTest {
    public static void main(String[] args) {
        String str = "中国";
        Charset utf8 = Charsets.UTF_8;
        String v1 = Hashing.md5().hashString(str,utf8).toString();
        System.out.println("md5="+v1+",len="+v1.length());

        String v2 = Hashing.sha256().hashString(str,utf8).toString();
        System.out.println("sha256="+v2+",len="+v2.length());

        String v3 = Hashing.sha384().hashString(str,utf8).toString();
        System.out.println("sha384="+v3+",len="+v3.length());

        String v4 = Hashing.sha512().hashString(str,utf8).toString();
        System.out.println("sha512="+v4+",len="+v4.length());

        String v5 = Hashing.sha1().hashString(str,utf8).toString();
        System.out.println("sha1="+v5+",len="+v5.length());

        String v6 = Hashing.adler32().hashString(str,utf8).toString();
        System.out.println("adler32="+v6+",len="+v6.length());

        String v7 = Hashing.crc32().hashString(str,utf8).toString();
        System.out.println("crc32="+v7+",len="+v7.length());

        String v8 = Hashing.crc32c().hashString(str,utf8).toString();
        System.out.println("crc32c="+v8+",len="+v8.length());

        String v9 = Hashing.farmHashFingerprint64().hashString(str,utf8).toString();
        System.out.println("farmHashFingerprint64="+v9+",len="+v9.length());

        String v10 = Hashing.fingerprint2011().hashString(str,utf8).toString();
        System.out.println("fingerprint2011="+v10+",len="+v10.length());

        String v11 = Hashing.goodFastHash(32).hashString(str,utf8).toString();
        System.out.println("goodFastHash="+v11+",len="+v11.length());

        String v12 = Hashing.murmur3_32_fixed().hashString(str,utf8).toString();
        System.out.println("murmur3_32_fixed="+v12+",len="+v12.length());

        String v13 = Hashing.murmur3_128().hashString(str,utf8).toString();
        System.out.println("murmur3_128="+v13+",len="+v13.length());

        String v14 = Hashing.sipHash24().hashString(str,utf8).toString();
        System.out.println("sipHash24="+v14+",len="+v14.length());

    }
}
